/*
 * TopDownProdHandler.java
 *
 * Created on March 30, 2007, 9:51 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.group1E;

import java.sql.*;

/**
 *
 * @author tkulbeth
 */
public class TopDownProdHandler {
    
    /**
     * Contains an instance of TopDownProdHandler
     */
    private static TopDownProdHandler instance = null;
    
    /**
     * Creates a new instance of TopDownProdHandler
     */
    public TopDownProdHandler() {}
    
    /**Retrieves an instance of the TopDownProdHandler object
     *@return instance of TopDownProdHandler
     */
    public static synchronized TopDownProdHandler getInstance() {
        if (instance == null) {
            instance = new TopDownProdHandler();
        }
        return instance;
    }

    
    /** Retrieves the type of product according to the 
     *ProductID.
     *@param id contains the ProductID for the object.
     *@return the type of product that will be used to find the
     *appropriate DAO to retrieve the product.
     */
    public synchronized String getProdType(String id, Connection conn){
            String type = "";
            try {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT ProdType FROM Product WHERE ProductID = '" + id + "'");
            conn.commit();

            //retrieve the type and send it back
            if (rs.next()) {
                type = rs.getString("ProdType");
            }
        }catch (SQLException ex) {
            ex.printStackTrace();
        }
        return type;
    }
    
}
